// useRef：实现子组件功能访问
import { forwardRef, useImperativeHandle, useRef } from "react"
const Child = forwardRef(function(props,ref){

    useImperativeHandle(ref,()=>({
        // 暴露给父组件的方法
        myFn:()=>(
            console.log("子组件的myFn方法")
        )
    }))

    return <div>子组件</div>
})
export default function UseRef(){
    const childRef = useRef()
    function handleClick(){
        childRef.current.myFn()
    }
    return (
        <div>
            <Child ref={childRef}></Child>
            <button onClick={handleClick}>+</button>
        </div>
    )
}